import { createStore } from 'vuex'

export const store = createStore({
  state () {
    return {
      nickname: localStorage.getItem('nickname') ? localStorage.getItem('nickname') :null,
      avatar:localStorage.getItem('avatar') ? localStorage.getItem('avatar') :null,
      schedule:localStorage.getItem('schedule') ? localStorage.getItem('schedule') :null
    }
  },
  mutations: {
    setNickName(state, nickname) {
      state.nickname = nickname.nickname
      localStorage.setItem('nickname',nickname.nickname)
    },
    setAvatar(state,avatar) {
      state.avatar = avatar.avatar
      localStorage.setItem('avatar',avatar.avatar)
    },
    setSchedule(state,schedule){
      state.schedule = schedule.schedule
      localStorage.setItem('schedule',schedule.schedule)
    }
  },
  getters: {
    getNickName(state) {
      return state.nickname
    },
    getAvatar(state) {
      return state.avatar
    },
    getSchedule(state) {
      return state.schedule
    }
  }
})